DonationAccount = function() {
	donationAccountThis = this;
	//클래스에서 사용하는 this
	donationAccountThis.bookingDonationAccountJson = null;
	//클래스에서 사용하는 jsonData
	donationAccountThis._HTMLDom = null;

	billingType = null;
	//결제수단 0=핸드폰 결제
}
DonationAccount.prototype = {
	donationAccountDetailView : function() {
		var mj = new MJson();
		var cm = new ConnectionManager();

		mj.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);
		mj.putPub(MJson.PUB.SID, "DR001");
		mj.putPub(MJson.PUB.SERVICENAME, "DonationDetailView");

		mj.putParameter("reserveSeq", document.globalObj.DONATION_DATA.donation_seq);

		console.log("request : " + mj.getJsonString());
		cm.requestGet(mj.getJsonString(), function(jsonData) {
			console.log("성공 :: 통신");
			if (mj.checkServiceResult(jsonData)) {
				console.log('donationAccountDetailView :: 성공');
				console.log("success :: " + JSON.stringify(jsonData));
				donationAccountThis.bookingDonationAccountJson = jsonData;

				//------- UI Display -------//
				var $donationHeader = donationAccountThis._HTMLDom.donationHeader;
				var $donationHeaderDt = donationAccountThis._HTMLDom.donationHeaderDt;
				var $donationHeaderDd = donationAccountThis._HTMLDom.donationHeaderDd;
				var $donationContents = donationAccountThis._HTMLDom.donationContents;
				var $donationContentsDd = donationAccountThis._HTMLDom.donationContentsDd;
				var $donationInput = donationAccountThis._HTMLDom.donationInput;
				var $donationInputRadio = donationAccountThis._HTMLDom.donationInputRadio;
				var $donationNextBtn = donationAccountThis._HTMLDom.donationNextBtn;

				var applicationDate = '<em>신청기간  :</em>' + jsonData.msp.contents.items.startDt + "~" + jsonData.msp.contents.items.endDt;
				$donationHeaderDt.find('p:eq(0)').html(applicationDate);

				var publicDate = (jsonData.msp.contents.items.publicDate ? jsonData.msp.contents.items.publicDate : jsonData.msp.contents.items.reservDate)
				var publicationDate = '<em>당첨자발표  :</em>' + publicDate;
				$donationHeaderDt.find('p:eq(1)').html(publicationDate);

				var holeCount = new String(jsonData.msp.contents.items.holeCnt);
				var donationTitle = jsonData.msp.contents.items.courseInfoNm + '<em>' + holeCount.slice(0, (holeCount.length - 1)) + 'H</em>';
				$donationHeaderDd.find('h5').html(donationTitle);

				var donationRoundDate = '<em>라운드날짜</em>' + jsonData.msp.contents.items.reservDate + '(' + jsonData.msp.contents.items.bookingDay + ')';
				$donationHeaderDd.find('li:eq(0)').html(donationRoundDate);

				var teaTime = '<em>티타임</em>' + jsonData.msp.contents.items.bookingTime;
				$donationHeaderDd.find('li:eq(1)').html(teaTime);

				var fee = addPeriod(jsonData.msp.contents.items.greenFee);
				var greenFee = '<em>1인 그린피</em><mark>￦' + fee + '</mark>';
				$donationHeaderDd.find('li:eq(2)').html(greenFee);

				$donationHeader.append($donationHeaderDt);
				$donationHeader.append($donationHeaderDd);

				var donatePrice = '응모 <mark>￦ ' + addPeriod(jsonData.msp.contents.items.donatePrice) + '</mark>';
				$donationContentsDd.html(donatePrice);

				$donationContents.append($donationContentsDd);
				//--------------------------//

			} else {
				console.log('donationAccountDetailView :: 실패');
			}
		}, function(e) {
			console.log("실패 :: 통신");
		});
	},
	donationReservApply : function() {
		var mj = new MJson();
		var cm = new ConnectionManager();

		mj.putPub(MJson.PUB.SID, "DR001");
		mj.putPub(MJson.PUB.SERVICENAME, "DonationReservApply");
		//mj.putPub("listcount", "10");
		//mj.putPub("currpageno", "1");

		mj.putParameter("reserveSeq", document.globalObj.DONATION_DATA.donation_seq);
		mj.putParameter("donatePrice", donationAccountThis.bookingDonationAccountJson.msp.contents.items.greenFee);
		mj.putParameter("card_number", "100010001");
		mj.putParameter("exp_year", "18");
		mj.putParameter("pay_amt", "1000");
		mj.putParameter("exp_month", "08");
		mj.putParameter("card_pw", "48");
		mj.putParameter("card_id_no", "1029918");
		mj.putParameter("card_quota", "00");

		console.log("request : " + mj.getJsonString());
		cm.requestGet(mj.getJsonString(), function(jsonData) {
			console.log("성공 :: 통신");
			
			if (mj.checkServiceResult(jsonData)) {
				console.log('donationReservApply :: 성공');
				console.log("success :: " + JSON.stringify(jsonData));

			} else {
				console.log('donationAccountDetailView :: 실패');
				console.log("fail :: " + JSON.stringify(jsonData));
				
			}
		}, function(e) {
			console.log("실패 :: 통신");
		});
	},
	onPageShow : function() {
		console.log("DonationAccount :: onPageShow");
		this.donationAccountDetailView();
		var $donationHeader = $("#donation_account_header");
		var $donationHeaderDt = $donationHeader.find("dt:first");
		var $donationHeaderDd = $donationHeader.find("dd:first");

		var $donationContents = $("#donation_account_contents");
		var $donationContentsDd = $donationContents.find('dd:first');

		var $donationInput = $("#donation_account_input");
		var $donationInputRadio = $donationContents.find('input:first');
		var $donationInputlabel = $donationContents.find('label:first');

		var $donationNextBtn = $("#donation_account_next");

		$donationNextBtn.attr('href', '');
		$donationNextBtn.attr('data-transition', '');
		$donationHeader.empty();
		$donationContents.empty();
		this._HTMLDom = {
			"donationHeader" : $donationHeader,
			"donationHeaderDt" : $donationHeaderDt,
			"donationHeaderDd" : $donationHeaderDd,
			"donationContents" : $donationContents,
			"donationContentsDd" : $donationContentsDd,
			"donationInput" : $donationInput,
			"donationInputRadio" : $donationInputRadio,
			"donationNextBtn" : $donationNextBtn
		}

		$("#a1").bind('click', function(event) {
			console.log($(this).attr('value'));
			billingType = $(this).attr('value');
		});
		$("#a2").bind('click', function(event) {
			console.log($(this).attr('value'));
			billingType = $(this).attr('value');
		});
		$donationNextBtn.bind('click', function(event) {
			donationAccountThis.donationReservApply();
			$.mobile.changePage('donation_account_01.html');
		});

	}
}
function addPeriod(nStr) {
	nStr += '';
	x = nStr.split(',');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}